/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ch.zhaw.ads.list;

import java.util.ArrayList;

/**
 *
 * @author framet
 */
public class BananaStackImpl implements BananaStackI {

    private ArrayList<Integer> storage;

    public BananaStackImpl() {
        this.storage = new ArrayList<>();
    }

    @Override
    public void push(int obj) {
        storage.add(obj);
    }

    @Override
    public int pop() throws BananaStackException {
        int temp = top();
        storage.remove(storage.size() - 1);
        return temp;
    }

    @Override
    public int top() throws BananaStackException {
        if (!storage.isEmpty()) {
            return storage.get(storage.size() - 1);
        } else {
            throw new BananaStackException("Error:102 - Stack is empty.");
        }
    }

    @Override
    public boolean isEmpty() {
        return storage.isEmpty();
    }
}
